﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows;
using DotNetUI.Controls;
using Xc.DataAccess.CodeReader;
using Xc.DataAccess.CodeReader.Models;
using Microsoft.Win32;
using OpenCvSharp;

namespace Xc.Logics.CodeReaders.Themes
{
    public partial class Generic
    {
        private void DotNetButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (sender is DotNetButton button)
            {
                if (button.DataContext is ObservableCollection<CVKeyPoint> collection)
                {
                    collection.Add(new CVKeyPoint { });
                }
            }
        }

        private void DotNetButton_Click_1(object sender, RoutedEventArgs e)
        {
            if (sender is DotNetButton button)
            {
                if (button.DataContext is CVKeyPoint info)
                {
                    if (button.Tag is ItemsControl items && items.ItemsSource is ICollection<CVKeyPoint> infos)
                    {
                        infos.Remove(info);
                    }
                }
            }
        }

        private void AddCvPoint(object sender, RoutedEventArgs e)
        {
            if (sender is DotNetButton button)
            {
                if (button.Tag is ObservableCollection<ObservableCollection<CVPoint>> info)
                {
                    info.Add(new ObservableCollection<CVPoint> { });
                }
            }
        }

        private void DotNetButton_Click_2(object sender, RoutedEventArgs e)
        {
            if (sender is DotNetButton button)
            {
                if (button.Tag is ObservableCollection<CVPoint> info)
                {
                    info.Add(new CVPoint { });
                }
            }
        }

        private void DotNetButton_Click_3(object sender, RoutedEventArgs e)
        {
            if (sender is DotNetButton button)
            {
                if (button.Tag is ItemsControl info&& info.ItemsSource is ObservableCollection<CVPoint> infos&& button.DataContext is CVPoint vPoint)
                {
                    infos.Remove(vPoint);
                }
            }
        }

        private void DotNetButton_Click_4(object sender, RoutedEventArgs e)
        {
            if (sender is DotNetButton button)
            {
                if (button.Tag is ObservableCollection<ObservableCollection<CVPoint>> info&&button.DataContext is ObservableCollection<CVPoint> d)
                {
                    info.Remove(d);
                }
            }
        }

        private void DotNetButton_Click_5(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "图片文件|*.*";
            openFileDialog.Title = "选取文件";
            if (openFileDialog.ShowDialog()==true)
            {
                if (sender is DotNetButton button&&button.Tag is TextBox box)
                {
                    box.Text = openFileDialog.FileName;
                    button.DataContext=Cv2.ImRead(box.Text);
                }
            }
        }
    }
}
